<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <title>积分明细</title>
    <link rel="stylesheet" href="../style/base.css">
    <script src="https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>
    <script type="text/javascript" src="../js/paramsTool.js"></script>
    <script type="text/javascript" src="../../js/layer.js"></script>

</head>
<style type="text/css">
    /*红包列表*/
    .rbtop{font-size:15px;font-weight:bold;width:100%;height:50px;  line-height:50px;background:#36a2f9; color:#FFF; text-align:center; }/*7.27修改*/
    .rbtop #extract{position: absolute; right: 5px;top: 5px;font-size:14px; height: 40px; line-height: 40px; width: 100px;}
    .listnum{background:#f7f7f7; margin-top:5px;width:100%;height:40px; line-height:40px;border-top:1px solid #ddd;border-bottom:1px solid #ddd;-webkit-box-shadow:0 0px 8px black;-moz-box-shadow:0 10px 10px black;}
    .listnum .left{float:left;width:40%;color:#898989;margin-left:20px;font-size:14px;}
    .listnum .right{float:right;width:40%;color:#1457bf;margin-right:15px;font-size:14px;text-align:right;}
    .listnmn{background:#87CEFA;width:100%;height:40px;padding:1px 0;border-bottom: solid #ddd 1px; color:#000;display:block;overflow:hidden;}/*7.27修改*/
    .listmn{width:100%;height:40px;padding:1px 0;border-bottom: solid #ddd 1px; display:block; overflow:hidden;}
    .listbg_gray{background:#f7f7f7;}
    .listmn .mn,.listnmn .mn{ float:right;height:22px;line-height:22px; margin:10px 10px 0 0;text-align:right;font-size:14px; font-weight:bold;}/*8.26*/

    .listnmn .tm,.listmn .tm{width:150px; line-height:44px;float:left; padding:0 15px 0 15px; font-weight:bold;}/*8.26*/
</style>
<script>
    var host = window.location.origin;
    var params = queryString();
//    console.log('params:',JSON.stringify(params));
    var disOpenid,disUid,disPoin;

    if(params.disOpenid){
        disOpenid = params.disOpenid;
    }else {
        disOpenid = getCookie('disOpenid');
    }
    if(params.disUid){
        disUid = params.disUid;
    }else {
        disUid = getCookie('disUid');
    }
    if(params.disPoin && params.disPoin !='undefined'){
        disPoin = params.disPoin;
    }else {
        disPoin = getCookie('disPoin') || 10;
    }


    if(!disUid || !disOpenid){
        getDisWxCode();
    }

    $(function () {

        var layInd = layer.open({
            type: 2,
            content: '加载中...',
            success: function () {

                $.ajax({
                    url: host+ "/getPoinList",
                    type: "get",
                    dataType:'json',
                    async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                    cache:false,
                    headers: {"content-type":"application/json","disuid":disUid},
                    success:function(data){
                        if(data.code){
                            layer.close(layInd);
                            alert('error:'+data.info);
                        }else {

                            var list = data.list;

                            for(var i = 0;i<list.length;i++){
                                var listmn=$("<div></div>").addClass('listmn');
                                var tm=$("<div>"+dateFormate(list[i].addDate)+"</div>").addClass('tm').appendTo(listmn);
                                if(list[i].action == 2){    //获得
                                    $("<div>"+list[i].target+"赠送"+list[i].poin+"积分</div>").addClass('mn').appendTo(listmn);
                                }else {             //送给
                                    $("<div>送给"+list[i].target+" : "+list[i].poin+"积分</div>").addClass('mn').appendTo(listmn);
                                }
                                listmn.appendTo($('#listDiv'));
                            }
                            $('#listNum').html(list.length);
                            $('#poin').html(disPoin);
                            layer.close(layInd);
                        }

                    },
                    error:function() {
                        layer.close(layInd);
                        alert('获取数据失败,请重试!');
                    }
                });
            }
        });

        $("#extract").click(function () {
            postClick();
        });

        function postClick(){
            if(disPoin > 0){

                layer.open({
                    content: '本次最多可赠送积分: ' +disPoin+' &nbsp;&nbsp;<label style="color: #36a2f9" onclick="popAll()"> 赠送全部</label> <br><br>'+
                    '赠送积分: <input id="popPoin" type="number" placeholder="请输入积分数量" style="border-bottom: 1px solid skyblue;padding-left: 5px; width: 120px; color:#36a2f9; font-size: 14px;"><br><br>'+
                    '赠送人ID: <input id="popUid" type="number" placeholder="请输入对方ID" style="border-bottom: 1px solid skyblue;padding-left: 5px; width: 120px; color:#36a2f9; font-size: 14px;"><br><br>'+
                    '<label style="color: #888">请按照正常交易流程,切勿不当操作,以免造成损失!</label>'
                    ,btn: ['确认赠送','取消赠送']
                    ,yes: function(index){
                        var sendPoin = $('#popPoin').val();
                        var tarUid = $('#popUid').val();

                        if(sendPoin > disPoin){

                            layer.open({
                                content: '积分不够哦!'
                                ,skin: 'msg'
                                ,time: 1.5 //2秒后自动关闭
                            });
                        }else if(!tarUid || tarUid<10200 || tarUid== disUid){
                            layer.open({
                                content: '请输入合法的ID号!'
                                ,skin: 'msg'
                                ,time: 1.5 //2秒后自动关闭
                            });
                        }else {
                            $.ajax({
                                url: host + "/sendPoin",
                                type: "post",
                                dataType: 'json',
                                async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                                headers: {
                                    "content-type": "application/json",
                                    "disopenid": disOpenid,
                                    "disuid": disUid
                                },
                                data:JSON.stringify({tarUid:tarUid,sendPoin:sendPoin}),
                                success: function (data) {

                                    if (data.code) {
                                        layer.open({
                                            content: data.info
                                            , skin: 'msg'
                                            , time: 1.5 //2秒后自动关闭
                                        });
                                    } else {
                                        layer.open({
                                            content: '赠送给'+tarUid+':'+sendPoin+'积分成功!'
                                            , btn: ['朕知道了']
                                            , yes: function (index) {
                                                layer.close(index);
                                            }
                                        });
                                        disPoin-=sendPoin;
                                        setCookie('disPoin',disPoin);
                                        $('#poin').html(disPoin);

                                        var listmn=$("<div></div>").addClass('listnmn');
                                        var tm=$("<div>"+dateFormate(new Date())+"</div>").addClass('tm').appendTo(listmn);
                                        $("<div>送给"+tarUid+" : "+sendPoin+"积分</div>").addClass('mn').appendTo(listmn);
                                        $('#listDiv').prepend(listmn);
                                    }
                                },
                                error: function () {
                                    layer.open({
                                        content: '提现失败,请重试!'
                                        , skin: 'msg'
                                        , time: 1.5 //2秒后自动关闭
                                    });
                                }

                            });
                            layer.close(index);
                        }
                    }
                });

            }else {
                layer.open({
                    content: '积分不够哦!'
                    ,skin: 'msg'
                    ,time: 1.5 //2秒后自动关闭
                });
            }
        }

    });
    function popAll(){
        $('#popPoin').val(disPoin);
    }
</script>
<body>


<!--顶部bar-->
<div class="rbtop">
   当前 <label id="poin">0</label> 积分
    <div id="extract">赠送积分</div>
</div>

<!--顶部bar结束-->
<div class="listnum">
    <div class="left">
        共 <label id="listNum" style="color: #36a2f9;font-weight: 600;">0</label> 条明细
    </div>
<!--</div>-->
<div class="hb_list" id="listDiv">

</div>
</body>
</html>
